<?php
	include_once "../include/Functions.php";
	
	session_start();
	$exercise_id= $_GET['exercise_id'];
	
	$person_id = $_SESSION['user_id'];
	$sql = "SELECT name, duration/1000 AS duration, TRUNCATE(distance,2) AS distance, TRUNCATE((speed*36)/10,2) AS speed
				FROM `exercise` 
				WHERE id = $exercise_id
				AND id_person = $person_id;";
	//echo $sql;
	$mat = Functions::getDataSql($sql);
			
	echo '<table>';
	echo '<tr><td>Name</td><td>'.$mat[0]['name'].'</td></tr>';
	echo '<tr><td>Duration</td><td>'.$mat[0]['duration'].' seconds</td></tr>';
	echo '<tr><td>Distance</td><td>'.$mat[0]['distance'].' kms</td></tr>';
	echo '<tr><td>Speed</td><td>'.$mat[0]['speed'].' km/h</td></tr>';
	echo '</table>';			
	echo '<hr>';
		
	$sql = "SELECT FROM_UNIXTIME(d_time/1000) AS d_time, lat, lon
				FROM `data_exerc` 
				WHERE id_exerc = $exercise_id
				AND id_person = $person_id;";
	//echo $sql;
	$mat = Functions::getDataSql($sql);
			
	echo '<table><tr><td>Time</td><td>Latitude</td><td>Longitude</td></tr>';
	for( $i=0; $i < count($mat); $i++ ) {
		echo '<tr><td>'.$mat[$i]['d_time'].'</td><td>'.$mat[$i]['lat'].'</td><td>'.$mat[$i]['lon'].'</td></tr>';
	}			
	echo '</table>';
?>